﻿Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Security.Permissions
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    <ActivityDesignerTheme(GetType(AmbientTheme), Xml:="<AmbientTheme xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/workflow"" ApplyTo=""System.Workflow.ComponentModel.Design.WorkflowView"" ShowConfigErrors=""True"" DrawShadow=""False"" DrawGrayscale=""False"" DropIndicatorColor=""0xFF006400"" SelectionForeColor=""0xFF0000FF"" SelectionPatternColor=""0xFF606060"" ForeColor=""0xFF808080"" BackColor=""0xFFFFFFFF"" ShowGrid=""False"" GridColor=""0xFFC0C0C0"" TextQuality=""Aliased"" DrawRounded=""True"" ShowDesignerBorder=""True"" />"), ToolboxItem(False)> _
    Public Class WorkflowView
        Inherits UserControl
        Implements IServiceProvider, IMessageFilter
        ' Events
        Public Custom Event Idle As EventHandler
            AddHandler(ByVal value As EventHandler)
                Me.idleEventListeners = DirectCast(Delegate.Combine(Me.idleEventListeners, value), EventHandler)
                If (Me.idleEventHandler Is Nothing) Then
                    Me.idleEventHandler = New EventHandler(AddressOf Me.OnWorkflowIdle)
                    Dim topLevelControl As Form = [TryCast](MyBase.TopLevelControl,Form)
                    If (Not Application.MessageLoop OrElse ((Not topLevelControl Is Nothing) AndAlso topLevelControl.Modal)) Then
                        WorkflowTimer.Default.Subscribe(100, Me.idleEventHandler)
                    Else
                        AddHandler Application.Idle, Me.idleEventHandler
                    End If
                End If
            End AddHandler
            RemoveHandler(ByVal value As EventHandler)
                Me.idleEventListeners = DirectCast(Delegate.Remove(Me.idleEventListeners, value), EventHandler)
                If ((Not Me.idleEventHandler Is Nothing) AndAlso (Me.idleEventListeners Is Nothing)) Then
                    Dim topLevelControl As Form = [TryCast](MyBase.TopLevelControl,Form)
                    If ((Not topLevelControl Is Nothing) AndAlso topLevelControl.Modal) Then
                        WorkflowTimer.Default.Unsubscribe(Me.idleEventHandler)
                    Else
                        RemoveHandler Application.Idle, Me.idleEventHandler
                    End If
                    Me.idleEventHandler = Nothing
                End If
            End RemoveHandler
        End Event
        Public Custom Event RootDesignerChanged As EventHandler
        Public Custom Event ZoomChanged As EventHandler

        ' Methods
        Public Sub New()
            Me.New(New DesignSurface)
        End Sub

        Public Sub New(ByVal serviceProvider As IServiceProvider)
            Me.zoomLevel = 1!
            Me.shadowDepth = WorkflowTheme.CurrentTheme.AmbientTheme.ShadowDepth
            Me.stockMessageFilters = New List([Of] WorkflowDesignerMessageFilter)
            Me.customMessageFilters = New List([Of] WorkflowDesignerMessageFilter)
            Me.prePreviewZoom = 100
            Me.prePreviewScroll = Point.Empty
            Me.messageHitTestContexts = New Stack([Of] HitTestInfo)
            If (serviceProvider Is Nothing) Then
                Throw New ArgumentNullException("serviceProvider")
            End If
            MyBase.SuspendLayout
            Me.AllowDrop = True
            Me.AutoScroll = False
            MyBase.HScroll = False
            MyBase.VScroll = False
            MyBase.SetStyle((ControlStyles.OptimizedDoubleBuffer Or (ControlStyles.EnableNotifyMessage Or (ControlStyles.AllPaintingInWmPaint Or (ControlStyles.Selectable Or (ControlStyles.Opaque Or ControlStyles.UserPaint))))), True)
            Me.serviceProvider = serviceProvider
            Dim container As IServiceContainer = [TryCast](Me.GetService(GetType(IServiceContainer)),IServiceContainer)
            If (Not container Is Nothing) Then
                container.RemoveService(GetType(WorkflowView))
                container.AddService(GetType(WorkflowView), Me)
            End If
            Dim service As IUIService = [TryCast](Me.serviceProvider.GetService(GetType(IUIService)),IUIService)
            If (Not service Is Nothing) Then
                WorkflowTheme.UIService = service
            End If
            Me.EnsureScrollBars(New HScrollBar, New VScrollBar)
            Me.workflowToolTip = New WorkflowToolTip(Me)
            AddHandler WorkflowTheme.ThemeChanged, New EventHandler(AddressOf Me.OnThemeChange)
            Me.PopulateMessageFilters(True)
            Me.RootDesigner = ActivityDesigner.GetSafeRootDesigner(Me)
            Me.fitAllAction = Me.CreateDynamicAction
            If ((Me.activeLayout Is Nothing) OrElse (Me.defaultLayout Is Nothing)) Then
                Me.ActiveLayout = Me.DefaultLayout = New WorkflowRootLayout(Me.serviceProvider)
            End If
            If TypeOf Me.GetService(GetType(IMenuCommandService)) Is IMenuCommandService Then
                Me.commandSet = New CommandSet(Me)
                Me.commandSet.UpdatePanCommands(True)
            End If
            Dim service3 As ISelectionService = [TryCast](Me.GetService(GetType(ISelectionService)),ISelectionService)
            If (Not service3 Is Nothing) Then
                AddHandler service3.SelectionChanged, New EventHandler(AddressOf Me.OnSelectionChanged)
            End If
            Application.AddMessageFilter(Me)
            MyBase.ResumeLayout(True)
        End Sub

        Public Sub AddDesignerMessageFilter(ByVal designerMessageFilter As WorkflowDesignerMessageFilter)
            If (designerMessageFilter Is Nothing) Then
                Throw New ArgumentNullException("designerMessageFilter")
            End If
            If MyBase.Capture Then
                MyBase.Capture = False
            End If
            Me.customMessageFilters.Insert(0, designerMessageFilter)
            designerMessageFilter.SetParentView(Me)
        End Sub

        Public Function ClientPointToLogical(ByVal clientPoint As Point) As Point
            Return Me.ClientPointToLogical(clientPoint, True)
        End Function

        Private Function ClientPointToLogical(ByVal point As Point, ByVal mapToLayout As Boolean) As Point
            Dim pts As Point() = New Point() { point }
            Dim matrix As New Matrix
            matrix.Translate(CSng(Me.ScrollPosition.X), CSng(Me.ScrollPosition.Y))
            matrix.TransformPoints(pts)
            Dim matrix2 As New Matrix
            matrix2.Scale(Me.ScaleZoomFactor, Me.ScaleZoomFactor)
            matrix2.Invert
            matrix2.TransformPoints(pts)
            matrix2.Invert
            If Not mapToLayout Then
                Return pts(0)
            End If
            Return Me.activeLayout.MapInCoOrdToLayout(pts(0))
        End Function

        Public Function ClientRectangleToLogical(ByVal rectangle As Rectangle) As Rectangle
            Dim logicalRectangle As New Rectangle(Me.ClientPointToLogical(rectangle.Location, False), Me.ClientSizeToLogical(rectangle.Size))
            Return Me.activeLayout.MapInRectangleToLayout(logicalRectangle)
        End Function

        Public Function ClientSizeToLogical(ByVal clientSize As Size) As Size
            Dim pts As Point() = New Point() { New Point(clientSize) }
            Dim matrix As New Matrix
            matrix.Scale(Me.ScaleZoomFactor, Me.ScaleZoomFactor)
            matrix.Invert
            matrix.TransformPoints(pts)
            matrix.Invert
            Return New Size(pts(0))
        End Function

        Protected Overrides Function CreateAccessibilityInstance() As AccessibleObject
            Return New WorkflowViewAccessibleObject(Me)
        End Function

        Private Function CreateDynamicAction() As DynamicAction
            Dim action As New DynamicAction { _
                .ButtonSize = ButtonSizes.Large, _
                .DockAlignment = DesignerContentAlignment.BottomRight, _
                .DockMargin = New Size(5, 5) _
            }
            Dim item As New ActionButton(New Image() { [TryCast](DR.GetImage("FitToScreen"),Bitmap) })
            AddHandler item.StateChanged, New EventHandler(AddressOf Me.OnFitToScreen)
            action.Buttons.Add(item)
            Return action
        End Function

        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                Try 
                    MyBase.SuspendLayout
                    Application.RemoveMessageFilter(Me)
                    If (Not Me.layoutEventHandler Is Nothing) Then
                        RemoveHandler Idle, Me.layoutEventHandler
                        Me.layoutEventHandler = Nothing
                    End If
                    If (Not Me.ensureVisibleEventHandler Is Nothing) Then
                        RemoveHandler Idle, Me.ensureVisibleEventHandler
                        Me.ensureVisibleEventHandler = Nothing
                    End If
                    If (Not Me.idleEventHandler Is Nothing) Then
                        Me.idleEventListeners = Nothing
                        Dim topLevelControl As Form = [TryCast](MyBase.TopLevelControl,Form)
                        If (Not Application.MessageLoop OrElse ((Not topLevelControl Is Nothing) AndAlso topLevelControl.Modal)) Then
                            WorkflowTimer.Default.Unsubscribe(Me.idleEventHandler)
                        Else
                            RemoveHandler Application.Idle, Me.idleEventHandler
                        End If
                        Me.idleEventHandler = Nothing
                    End If
                    Dim service As ISelectionService = [TryCast](Me.GetService(GetType(ISelectionService)),ISelectionService)
                    If (Not service Is Nothing) Then
                        RemoveHandler service.SelectionChanged, New EventHandler(AddressOf Me.OnSelectionChanged)
                    End If
                    RemoveHandler WorkflowTheme.ThemeChanged, New EventHandler(AddressOf Me.OnThemeChange)
                    If (Not Me.fitAllAction Is Nothing) Then
                        Me.fitAllAction.Dispose
                        Me.fitAllAction = Nothing
                    End If
                    If (Not Me.workflowToolTip Is Nothing) Then
                        DirectCast(Me.workflowToolTip, IDisposable).Dispose
                        Me.workflowToolTip = Nothing
                    End If
                    Me.DisposeMessageFilters(False)
                    Me.DisposeMessageFilters(True)
                    Me.activeLayout = Nothing
                    If (Not Me.defaultLayout Is Nothing) Then
                        Me.defaultLayout.Dispose
                        Me.defaultLayout = Nothing
                    End If
                    If (Not Me.viewPortBitmap Is Nothing) Then
                        Me.viewPortBitmap.Dispose
                        Me.viewPortBitmap = Nothing
                    End If
                    If (Not Me.commandSet Is Nothing) Then
                        Me.commandSet.Dispose
                        Me.commandSet = Nothing
                    End If
                    RemoveHandler Me.HScrollBar.ValueChanged, New EventHandler(AddressOf Me.OnScroll)
                    RemoveHandler Me.VScrollBar.ValueChanged, New EventHandler(AddressOf Me.OnScroll)
                    If (Not Me.toolContainer Is Nothing) Then
                        MyBase.Controls.Remove(Me.toolContainer)
                        Me.toolContainer.TabStrip.Tabs.Clear
                        Me.toolContainer.Dispose
                        Me.toolContainer = Nothing
                    End If
                    Dim container As IServiceContainer = [TryCast](Me.GetService(GetType(IServiceContainer)),IServiceContainer)
                    If (Not container Is Nothing) Then
                        container.RemoveService(GetType(WorkflowView))
                    End If
                Finally
                    MyBase.ResumeLayout(False)
                End Try
            End If
            MyBase.Dispose(disposing)
        End Sub

        Private Sub DisposeMessageFilters(ByVal stockFilters As Boolean)
            Dim list As List([Of] WorkflowDesignerMessageFilter) = If(stockFilters, Me.stockMessageFilters, Me.customMessageFilters)
            Dim list2 As New ArrayList(list.ToArray)
            Dim filter As WorkflowDesignerMessageFilter
            For Each filter In list2
                filter.Dispose
            Next
            list.Clear
        End Sub

        Private Sub EnsureScrollBars(ByVal newHorizScrollBar As HScrollBar, ByVal newVertScrollBar As VScrollBar)
            Try 
                MyBase.SuspendLayout
                If (Not Me.hScrollBar Is newHorizScrollBar) Then
                    If (Not Me.hScrollBar Is Nothing) Then
                        RemoveHandler Me.hScrollBar.ValueChanged, New EventHandler(AddressOf Me.OnScroll)
                        If MyBase.Controls.Contains(Me.hScrollBar) Then
                            MyBase.Controls.Remove(Me.hScrollBar)
                        End If
                    End If
                    Me.hScrollBar = newHorizScrollBar
                    If (Me.hScrollBar.Parent Is Nothing) Then
                        Me.hScrollBar.TabStop = False
                        MyBase.Controls.Add(Me.hScrollBar)
                    End If
                End If
                If (Not Me.vScrollBar Is newVertScrollBar) Then
                    If (Not Me.vScrollBar Is Nothing) Then
                        RemoveHandler Me.vScrollBar.ValueChanged, New EventHandler(AddressOf Me.OnScroll)
                        If MyBase.Controls.Contains(Me.vScrollBar) Then
                            MyBase.Controls.Remove(Me.vScrollBar)
                        End If
                    End If
                    Me.vScrollBar = newVertScrollBar
                    If (Me.vScrollBar.Parent Is Nothing) Then
                        Me.vScrollBar.TabStop = False
                        MyBase.Controls.Add(Me.vScrollBar)
                    End If
                End If
                AddHandler Me.hScrollBar.ValueChanged, New EventHandler(AddressOf Me.OnScroll)
                AddHandler Me.vScrollBar.ValueChanged, New EventHandler(AddressOf Me.OnScroll)
            Finally
                MyBase.ResumeLayout(True)
            End Try
        End Sub

        Private Sub EnsureVisible(ByVal rect As Rectangle)
            Dim rectangle As Rectangle = Me.ClientRectangleToLogical(New Rectangle(Point.Empty, Me.ViewPortSize))
            If (Not rectangle.Contains(rect.Location) OrElse Not rectangle.Contains(New Point(rect.Right, rect.Bottom))) Then
                Dim logicalSize As New Size
                If (Not rectangle.Contains(New Point(rect.Left, rectangle.Top)) OrElse Not rectangle.Contains(New Point(rect.Right, rectangle.Top))) Then
                    If (rect.Width > rectangle.Width) Then
                        logicalSize.Width = ((rect.Left + (rect.Width / 2)) - (rectangle.Left + (rectangle.Width / 2)))
                    ElseIf (rect.Left < rectangle.Left) Then
                        logicalSize.Width = (rect.Left - rectangle.Left)
                    Else
                        logicalSize.Width = (rect.Right - rectangle.Right)
                    End If
                End If
                If (Not rectangle.Contains(New Point(rectangle.Left, rect.Top)) OrElse Not rectangle.Contains(New Point(rectangle.Left, rect.Bottom))) Then
                    If ((rect.Top < rectangle.Top) OrElse (rect.Height > rectangle.Height)) Then
                        logicalSize.Height = (rect.Top - rectangle.Top)
                    Else
                        logicalSize.Height = (rect.Bottom - rectangle.Bottom)
                    End If
                End If
                logicalSize = Me.LogicalSizeToClient(logicalSize)
                Dim scrollPosition As Point = Me.ScrollPosition
                Me.ScrollPosition = New Point((scrollPosition.X + logicalSize.Width), (scrollPosition.Y + logicalSize.Height))
            End If
        End Sub

        Public Sub EnsureVisible(ByVal selectableObject As Object)
            If (selectableObject Is Nothing) Then
                Throw New ArgumentNullException("selectableObject")
            End If
            Dim activity As Activity = [TryCast](selectableObject,Activity)
            Do While (Not activity Is Nothing)
                Dim containedDesigner As ActivityDesigner = ActivityDesigner.GetDesigner(activity)
                Dim parentDesigner As CompositeActivityDesigner = containedDesigner.ParentDesigner
                If (Not parentDesigner Is Nothing) Then
                    If (Not containedDesigner Is Nothing) Then
                        parentDesigner.EnsureVisibleContainedDesigner(containedDesigner)
                    End If
                    activity = parentDesigner.Activity
                Else
                    activity = Nothing
                End If
            Loop
            activity = [TryCast](selectableObject,Activity)
            If (Not activity Is Nothing) Then
                Dim designer As CompositeActivityDesigner = [TryCast](ActivityDesigner.GetDesigner(activity),CompositeActivityDesigner)
                If (Not designer Is Nothing) Then
                    designer.EnsureVisibleContainedDesigner(designer)
                End If
            End If
            Me.PerformLayout(False)
            If (Me.ensureVisibleEventHandler Is Nothing) Then
                Me.ensureVisibleEventHandler = New EventHandler(AddressOf Me.OnEnsureVisible)
                AddHandler Idle, Me.ensureVisibleEventHandler
            End If
        End Sub

        Public Sub FitToScreenSize()
            If ((Me.HScrollBar.Maximum > Me.ViewPortSize.Width) OrElse (Me.VScrollBar.Maximum > Me.ViewPortSize.Height)) Then
                Dim num As Integer = CInt(((100! / Me.ActiveLayout.Scaling) * Math.Min(CSng((CSng(Me.ViewPortSize.Width) / CSng(Me.ActiveLayout.Extent.Width))), CSng((CSng(Me.ViewPortSize.Height) / CSng(Me.ActiveLayout.Extent.Height))))))
                Me.Zoom = Math.Min(Math.Max(num, 10), 400)
            End If
        End Sub

        Public Sub FitToWorkflowSize()
            If (Me.Zoom <> 100) Then
                Me.Zoom = 100
            End If
        End Sub

        Protected Overrides Function GetService(ByVal serviceType As Type) As Object
            If (serviceType Is GetType(CommandID)) Then
                Return New CommandID(New Guid("5f1c3c8d-60f1-4b98-b85b-8679f97e8eac"), 0)
            End If
            Return Me.serviceProvider.GetService(serviceType)
        End Function

        Public Sub InvalidateClientRectangle(ByVal clientRectangle As Rectangle)
            If (Me.layoutEventHandler Is Nothing) Then
                If Not clientRectangle.IsEmpty Then
                    clientRectangle.Inflate(1, 1)
                    MyBase.Invalidate(clientRectangle)
                Else
                    MyBase.Invalidate
                End If
            End If
        End Sub

        Public Sub InvalidateLogicalRectangle(ByVal logicalRectangle As Rectangle)
            Me.InvalidateClientRectangle(Me.LogicalRectangleToClient(logicalRectangle))
        End Sub

        Friend Function IsClientPointInActiveLayout(ByVal clientPoint As Point) As Boolean
            Dim logicalCoOrd As Point = Me.ClientPointToLogical(clientPoint, False)
            Return Me.activeLayout.IsCoOrdInLayout(logicalCoOrd)
        End Function

        Public Sub LoadViewState(ByVal viewState As Stream)
            If (viewState Is Nothing) Then
                Throw New ArgumentNullException("viewState")
            End If
            Dim point As New Point(0, 0)
            Dim service As IDesignerHost = DirectCast(Me.GetService(GetType(IDesignerHost)), IDesignerHost)
            If (service Is Nothing) Then
                Throw New Exception(SR.GetString("General_MissingService", New Object() { GetType(IDesignerHost).FullName }))
            End If
            viewState.Position = 0
            Dim reader As New BinaryReader(viewState)
            Me.PrintPreviewMode = reader.ReadBoolean
            Me.Zoom = reader.ReadInt32
            Try 
                If Not DesignerHelpers.DeserializeDesignerStates(service, reader) Then
                    point.X = reader.ReadInt32
                    point.Y = reader.ReadInt32
                End If
            Finally
                MyBase.PerformLayout
                Me.ScrollPosition = point
            End Try
        End Sub

        Public Function LogicalPointToClient(ByVal logicalPoint As Point) As Point
            Return Me.LogicalPointToClient(logicalPoint, True)
        End Function

        Private Function LogicalPointToClient(ByVal point As Point, ByVal mapToLayout As Boolean) As Point
            If mapToLayout Then
                point = Me.activeLayout.MapOutCoOrdFromLayout(point)
            End If
            Dim matrix As New Matrix
            matrix.Scale(Me.ScaleZoomFactor, Me.ScaleZoomFactor)
            Dim pts As Point() = New Point() { point }
            matrix.TransformPoints(pts)
            Dim matrix2 As New Matrix
            matrix2.Translate(CSng(-Me.ScrollPosition.X), CSng(-Me.ScrollPosition.Y))
            matrix2.TransformPoints(pts)
            Return pts(0)
        End Function

        Public Function LogicalPointToScreen(ByVal logicalPoint As Point) As Point
            Return MyBase.PointToScreen(Me.LogicalPointToClient(logicalPoint))
        End Function

        Public Function LogicalRectangleToClient(ByVal rectangle As Rectangle) As Rectangle
            Dim rectangle2 As Rectangle = If((Not Me.activeLayout Is Nothing), Me.activeLayout.MapOutRectangleFromLayout(rectangle), rectangle)
            Return New Rectangle(Me.LogicalPointToClient(rectangle2.Location, False), Me.LogicalSizeToClient(rectangle2.Size))
        End Function

        Public Function LogicalSizeToClient(ByVal logicalSize As Size) As Size
            Dim pts As Point() = New Point() { New Point(logicalSize) }
            Dim matrix As New Matrix
            matrix.Scale(Me.ScaleZoomFactor, Me.ScaleZoomFactor)
            matrix.TransformPoints(pts)
            Return New Size(pts(0))
        End Function

        Friend Sub OnCommandKey(ByVal e As KeyEventArgs)
            Me.OnKeyDown(e)
            Me.OnKeyUp(e)
        End Sub

        Protected Overrides Sub OnControlAdded(ByVal e As ControlEventArgs)
            If (((Not e.Control Is Me.VScrollBar) AndAlso (Not e.Control Is Me.HScrollBar)) AndAlso (Not e.Control Is Me.toolContainer)) Then
                Throw New InvalidOperationException(SR.GetString("Error_InsertingChildControls"))
            End If
        End Sub

        Protected Overrides Sub OnDragDrop(ByVal dragEventArgs As DragEventArgs)
            MyBase.OnDragDrop(dragEventArgs)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, dragEventArgs)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnDragDrop(dragEventArgs) Then
                        goto Label_004D
                    End If
                Next
            End [Using]
        Label_004D:
            Me.dragDropInProgress = False
        End Sub

        Protected Overrides Sub OnDragEnter(ByVal dragEventArgs As DragEventArgs)
            MyBase.OnDragEnter(dragEventArgs)
            Me.dragDropInProgress = True
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, dragEventArgs)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnDragEnter(dragEventArgs) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnDragLeave(ByVal e As EventArgs)
            MyBase.OnDragLeave(e)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, EventArgs.Empty)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnDragLeave Then
                        goto Label_0050
                    End If
                Next
            End [Using]
        Label_0050:
            Me.dragDropInProgress = False
        End Sub

        Protected Overrides Sub OnDragOver(ByVal dragEventArgs As DragEventArgs)
            MyBase.OnDragOver(dragEventArgs)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, dragEventArgs)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnDragOver(dragEventArgs) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Private Sub OnEnsureVisible(ByVal sender As Object, ByVal e As EventArgs)
            If (Not Me.ensureVisibleEventHandler Is Nothing) Then
                RemoveHandler Idle, Me.ensureVisibleEventHandler
                Me.ensureVisibleEventHandler = Nothing
            End If
            Dim service As ISelectionService = DirectCast(Me.GetService(GetType(ISelectionService)), ISelectionService)
            If ((Not service Is Nothing) AndAlso (service.SelectionCount > 0)) Then
                Dim list As New ArrayList(service.GetSelectedComponents)
                Dim i As Integer = (list.Count - 1)
                Do While (i >= 0)
                    Dim empty As Rectangle = Rectangle.Empty
                    If TypeOf list.Item(i) Is Activity Then
                        Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner([TryCast](list.Item(i),Activity))
                        If (Not designer Is Nothing) Then
                            empty = designer.Bounds
                            empty.Inflate(WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize)
                            empty.Inflate(WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize)
                        End If
                    ElseIf TypeOf list.Item(i) Is HitTestInfo Then
                        empty = DirectCast(list.Item(i), HitTestInfo).Bounds
                    End If
                    If Not empty.IsEmpty Then
                        Me.EnsureVisible(empty)
                    End If
                    i -= 1
                Loop
            End If
        End Sub

        Private Sub OnFitToScreen(ByVal sender As Object, ByVal e As EventArgs)
            Dim button As ActionButton = [TryCast](sender,ActionButton)
            If ((Not button Is Nothing) AndAlso (button.State = States.Pressed)) Then
                If ((Me.HScrollBar.Maximum > Me.ViewPortSize.Width) OrElse (Me.VScrollBar.Maximum > Me.ViewPortSize.Height)) Then
                    Me.FitToScreenSize
                ElseIf (Me.Zoom <> 100) Then
                    Me.FitToWorkflowSize
                End If
            End If
        End Sub

        Protected Overrides Sub OnGiveFeedback(ByVal gfbevent As GiveFeedbackEventArgs)
            MyBase.OnGiveFeedback(gfbevent)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, gfbevent)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnGiveFeedback(gfbevent) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, e)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnKeyDown(e) Then
                        goto Label_0046
                    End If
                Next
            End [Using]
        Label_0046:
            If Not e.Handled Then
                MyBase.OnKeyDown(e)
            End If
        End Sub

        Protected Overrides Sub OnKeyUp(ByVal e As KeyEventArgs)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, e)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnKeyUp(e) Then
                        goto Label_0046
                    End If
                Next
            End [Using]
        Label_0046:
            If Not e.Handled Then
                MyBase.OnKeyUp(e)
            End If
        End Sub

        Protected Overrides Sub OnLayout(ByVal levent As LayoutEventArgs)
            MyBase.OnLayout(levent)
            Dim hScrollBar As ScrollBar = Me.HScrollBar
            Dim vScrollBar As ScrollBar = Me.VScrollBar
            If MyBase.Controls.Contains(hScrollBar) Then
                hScrollBar.Bounds = New Rectangle(0, Math.Max(0, (MyBase.Height - SystemInformation.HorizontalScrollBarHeight)), Math.Max((MyBase.Width - If(vScrollBar.Visible, SystemInformation.VerticalScrollBarWidth, 0)), 0), SystemInformation.HorizontalScrollBarHeight)
            End If
            If MyBase.Controls.Contains(vScrollBar) Then
                vScrollBar.Bounds = New Rectangle(Math.Max(0, (MyBase.Width - SystemInformation.VerticalScrollBarWidth)), 0, SystemInformation.VerticalScrollBarWidth, Math.Max((MyBase.Height - If(hScrollBar.Visible, SystemInformation.HorizontalScrollBarHeight, 0)), 0))
            End If
            If (Not Me.toolContainer Is Nothing) Then
                Me.toolContainer.Location = New Point((MyBase.Width - Me.toolContainer.Width), 0)
                Me.toolContainer.Height = (MyBase.Height - If(hScrollBar.Visible, hScrollBar.Height, 0))
            End If
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, levent)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    DirectCast(filter, IWorkflowDesignerMessageSink).OnLayout(levent)
                Next
            End [Using]
            [Using] graphics As Graphics = MyBase.CreateGraphics
                Me.activeLayout.Update(graphics, LayoutUpdateReason.LayoutChanged)
                If (Not Me.rootDesigner Is Nothing) Then
                    Me.rootDesigner.Location = Me.activeLayout.RootDesignerAlignment
                End If
            End [Using]
            Me.UpdateScrollRange
            Me.InvalidateClientRectangle(Rectangle.Empty)
        End Sub

        Protected Overrides Sub OnMouseCaptureChanged(ByVal e As EventArgs)
            MyBase.OnMouseCaptureChanged(e)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, EventArgs.Empty)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseCaptureChanged Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnMouseDoubleClick(ByVal e As MouseEventArgs)
            MyBase.OnMouseDoubleClick(e)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, e)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseDoubleClick(e) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
            MyBase.OnMouseDown(e)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, e)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseDown(e) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
            MyBase.OnMouseEnter(e)
            Dim point As Point = MyBase.PointToClient(Control.MousePosition)
            Dim args As New MouseEventArgs(Control.MouseButtons, 1, point.X, point.Y, 0)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, args)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseEnter(args) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnMouseHover(ByVal e As EventArgs)
            MyBase.OnMouseHover(e)
            Dim point As Point = MyBase.PointToClient(Control.MousePosition)
            Dim args As New MouseEventArgs(Control.MouseButtons, 1, point.X, point.Y, 0)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, args)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseHover(args) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
            MyBase.OnMouseLeave(e)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, EventArgs.Empty)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseLeave Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
            MyBase.OnMouseMove(e)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, e)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseMove(e) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
            MyBase.OnMouseUp(e)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, e)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseUp(e) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
            MyBase.OnMouseWheel(e)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, e)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnMouseWheel(e) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            MyBase.OnPaint(e)
            Dim container As GraphicsContainer = e.Graphics.BeginContainer
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality
            Dim flag As Boolean = ((Me.viewPortBitmap Is Nothing) OrElse (Me.viewPortBitmap.Size <> Me.ViewPortSize))
            If flag Then
                If (Not Me.viewPortBitmap Is Nothing) Then
                    Me.viewPortBitmap.Dispose
                End If
                Me.viewPortBitmap = New Bitmap(Math.Max(1, Me.ViewPortSize.Width), Math.Max(1, Me.ViewPortSize.Height), e.Graphics)
            End If
            Dim viewPortData As New ViewPortData { _
                .LogicalViewPort = Me.ClientRectangleToLogical(New Rectangle(Point.Empty, Me.ViewPortSize)), _
                .MemoryBitmap = Me.viewPortBitmap, _
                .Scaling = New SizeF(Me.ScaleZoomFactor, Me.ScaleZoomFactor), _
                .Translation = Me.ScrollPosition, _
                .ShadowDepth = New Size(Me.shadowDepth, Me.shadowDepth), _
                .ViewPortSize = Me.ViewPortSize _
            }
            If ((Me.layoutEventHandler Is Nothing) OrElse flag) Then
                WorkflowView.TakeWorkflowSnapShot(Me, viewPortData)
            End If
            Try 
                Me.activeLayout.OnPaintWorkflow(e, viewPortData)
            Catch exception1 As Exception
            End Try
            [Using] data2 As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, EventArgs.Empty)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data2.Filters
                    Try 
                        If DirectCast(filter, IWorkflowDesignerMessageSink).OnPaintWorkflowAdornments(e, Me.ViewPortRectangle) Then
                            goto Label_01A0
                        End If
                        [Continue] For
                    Catch exception2 As Exception
                        [Continue] For
                    End Try
                Next
            End [Using]
        Label_01A0:
            e.Graphics.EndContainer(container)
            e.Graphics.FillRectangle(SystemBrushes.Control, New Rectangle((MyBase.Width - SystemInformation.VerticalScrollBarWidth), (MyBase.Height - SystemInformation.HorizontalScrollBarHeight), SystemInformation.VerticalScrollBarWidth, SystemInformation.HorizontalScrollBarHeight))
        End Sub

        Private Sub OnPerformLayout(ByVal sender As Object, ByVal e As EventArgs)
            If (Not Me.layoutEventHandler Is Nothing) Then
                RemoveHandler Idle, Me.layoutEventHandler
                Me.layoutEventHandler = Nothing
                MyBase.PerformLayout
            End If
        End Sub

        Protected Overrides Sub OnQueryContinueDrag(ByVal qcdevent As QueryContinueDragEventArgs)
            MyBase.OnQueryContinueDrag(qcdevent)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, qcdevent)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).OnQueryContinueDrag(qcdevent) Then
                        Return
                    End If
                Next
            End [Using]
        End Sub

        Protected Overridable Sub OnRootDesignerChanged()
            If (Not Me.RootDesignerChanged Is Nothing) Then
                Me.RootDesignerChanged.Invoke(Me, EventArgs.Empty)
            End If
        End Sub

        Private Sub OnScroll(ByVal sender As Object, ByVal e As EventArgs)
            Me.InvalidateClientRectangle(Rectangle.Empty)
            Dim bar As ScrollBar = [TryCast](sender,ScrollBar)
            If (Not bar Is Nothing) Then
                [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, e)
                    Dim filter As WorkflowDesignerMessageFilter
                    For Each filter In data.Filters
                        Try 
                            DirectCast(filter, IWorkflowDesignerMessageSink).OnScroll(bar, bar.Value)
                            [Continue] For
                        Catch exception1 As Exception
                            [Continue] For
                        End Try
                    Next
                End [Using]
            End If
        End Sub

        Private Sub OnSelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
            If (Not Me.commandSet Is Nothing) Then
                Me.commandSet.UpdateCommandSet
            End If
            If ((Not Me.RootDesigner Is Nothing) AndAlso (Not Me.RootDesigner.Activity Is Nothing)) Then
                Dim service As ISelectionService = [TryCast](Me.GetService(GetType(ISelectionService)),ISelectionService)
                If ((Not service Is Nothing) AndAlso service.GetComponentSelected(Me.RootDesigner.Activity)) Then
                    Dim service2 As IHelpService = [TryCast](Me.GetService(GetType(IHelpService)),IHelpService)
                    If (Not service2 Is Nothing) Then
                        service2.AddContextAttribute("Keyword", Me.RootDesigner.Activity.GetType.FullName, HelpKeywordType.F1Keyword)
                    End If
                End If
            End If
        End Sub

        Private Sub OnTabChange(ByVal sender As Object, ByVal e As TabSelectionChangeEventArgs)
            If (((e.CurrentItem.Identifier = 1) OrElse (e.CurrentItem.Identifier = 2)) OrElse (e.CurrentItem.Identifier = 3)) Then
                Dim selectedTabBounds As Rectangle = e.SelectedTabBounds
                Dim menuID As CommandID = Nothing
                If (e.CurrentItem.Identifier = 1) Then
                    menuID = WorkflowMenuCommands.PageLayoutMenu
                ElseIf (e.CurrentItem.Identifier = 2) Then
                    menuID = WorkflowMenuCommands.ZoomMenu
                Else
                    menuID = WorkflowMenuCommands.PanMenu
                End If
                Dim service As IMenuCommandService = DirectCast(Me.GetService(GetType(IMenuCommandService)), IMenuCommandService)
                If (Not service Is Nothing) Then
                    service.ShowContextMenu(menuID, selectedTabBounds.Right, selectedTabBounds.Top)
                End If
            End If
        End Sub

        Friend Sub OnThemeChange(ByVal sender As Object, ByVal e As EventArgs)
            Me.ShadowDepth = WorkflowTheme.CurrentTheme.AmbientTheme.ShadowDepth
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, EventArgs.Empty)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    Try 
                        DirectCast(filter, IWorkflowDesignerMessageSink).OnThemeChange
                        [Continue] For
                    Catch exception1 As Exception
                        [Continue] For
                    End Try
                Next
            End [Using]
            MyBase.PerformLayout
        End Sub

        Private Sub OnWorkflowIdle(ByVal sender As Object, ByVal e As EventArgs)
            If (Not Me.idleEventListeners Is Nothing) Then
                Me.idleEventListeners.Invoke(Me, e)
            End If
        End Sub

        Protected Overridable Sub OnZoomChanged()
            If (Not Me.ZoomChanged Is Nothing) Then
                Me.ZoomChanged.Invoke(Me, EventArgs.Empty)
            End If
        End Sub

        Public Sub PerformLayout(ByVal immediateUpdate As Boolean)
            If immediateUpdate Then
                If (Not Me.layoutEventHandler Is Nothing) Then
                    RemoveHandler Idle, Me.layoutEventHandler
                    Me.layoutEventHandler = Nothing
                End If
                MyBase.PerformLayout
            ElseIf (Me.layoutEventHandler Is Nothing) Then
                Me.layoutEventHandler = New EventHandler(AddressOf Me.OnPerformLayout)
                AddHandler Idle, Me.layoutEventHandler
            End If
        End Sub

        Private Sub PopulateMessageFilters(ByVal stockFilters As Boolean)
            Dim list As IList([Of] WorkflowDesignerMessageFilter) = If(stockFilters, Me.stockMessageFilters, Me.customMessageFilters)
            If stockFilters Then
                list.Add(New GlyphManager)
                list.Add(New WindowManager)
            Else
                If MyBase.Capture Then
                    MyBase.Capture = False
                End If
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In DirectCast(Me.rootDesigner, IWorkflowRootDesigner).MessageFilters
                    list.Add(filter)
                Next
            End If
            Dim filter2 As WorkflowDesignerMessageFilter
            For Each filter2 In list
                filter2.SetParentView(Me)
            Next
        End Sub

        Private Sub RefreshDynamicAction()
            Dim service As DynamicActionMessageFilter = [TryCast](Me.GetService(GetType(DynamicActionMessageFilter)),DynamicActionMessageFilter)
            If ((Not service Is Nothing) AndAlso (Not Me.fitAllAction Is Nothing)) Then
                If ((Me.HScrollBar.Maximum > Me.ViewPortSize.Width) OrElse (Me.VScrollBar.Maximum > Me.ViewPortSize.Height)) Then
                    Me.fitAllAction.Buttons.Item(0).Description = DR.GetString("FitToScreenDescription", New Object(0  - 1) {})
                    Me.fitAllAction.Buttons.Item(0).StateImages = New Bitmap() { [TryCast](DR.GetImage("FitToScreen"),Bitmap) }
                    service.AddAction(Me.fitAllAction)
                ElseIf (Me.Zoom <> 100) Then
                    Me.fitAllAction.Buttons.Item(0).Description = DR.GetString("FitToWorkflowDescription", New Object(0  - 1) {})
                    Me.fitAllAction.Buttons.Item(0).StateImages = New Bitmap() { [TryCast](DR.GetImage("FitToWorkflow"),Bitmap) }
                    service.AddAction(Me.fitAllAction)
                Else
                    service.RemoveAction(Me.fitAllAction)
                    Me.fitAllAction.Buttons.Item(0).State = States.Normal
                End If
            End If
        End Sub

        Public Sub RemoveDesignerMessageFilter(ByVal designerMessageFilter As WorkflowDesignerMessageFilter)
            If (designerMessageFilter Is Nothing) Then
                Throw New ArgumentNullException("designerMessageFilter")
            End If
            If Me.customMessageFilters.Contains(designerMessageFilter) Then
                If MyBase.Capture Then
                    MyBase.Capture = False
                End If
                Me.customMessageFilters.Remove(designerMessageFilter)
                designerMessageFilter.Dispose
            End If
        End Sub

        Public Sub SaveViewState(ByVal viewState As Stream)
            If (viewState Is Nothing) Then
                Throw New ArgumentNullException("viewState")
            End If
            Dim service As IDesignerHost = DirectCast(Me.GetService(GetType(IDesignerHost)), IDesignerHost)
            If (service Is Nothing) Then
                Throw New Exception(SR.GetString("General_MissingService", New Object() { GetType(IDesignerHost).FullName }))
            End If
            Dim writer As New BinaryWriter(viewState)
            writer.Write(Me.PrintPreviewMode)
            writer.Write(Me.Zoom)
            DesignerHelpers.SerializeDesignerStates(service, writer)
            writer.Write(Me.ScrollPosition.X)
            writer.Write(Me.ScrollPosition.Y)
        End Sub

        Public Sub SaveWorkflowImage(ByVal stream As Stream, ByVal imageFormat As ImageFormat)
            If (stream Is Nothing) Then
                Throw New ArgumentNullException("stream")
            End If
            If (imageFormat Is Nothing) Then
                Throw New ArgumentNullException("imageFormat")
            End If
            Dim bitmap As Bitmap = Me.TakeWorkflowSnapShot
            If (Not bitmap Is Nothing) Then
                bitmap.Save(stream, imageFormat)
                bitmap.Dispose
            End If
        End Sub

        Public Sub SaveWorkflowImage(ByVal imageFile As String, ByVal imageFormat As ImageFormat)
            If (imageFile Is Nothing) Then
                Throw New ArgumentNullException("imageFile")
            End If
            If (imageFormat Is Nothing) Then
                Throw New ArgumentNullException("imageFormat")
            End If
            Dim bitmap As Bitmap = Me.TakeWorkflowSnapShot
            If (Not bitmap Is Nothing) Then
                bitmap.Save(imageFile, imageFormat)
                bitmap.Dispose
            End If
        End Sub

        Public Sub SaveWorkflowImageToClipboard()
            Dim data As Bitmap = Me.TakeWorkflowSnapShot
            If (Not data Is Nothing) Then
                Clipboard.SetDataObject(data, True)
                data.Dispose
            End If
        End Sub

        Public Function ScreenPointToLogical(ByVal screenPoint As Point) As Point
            Return Me.ClientPointToLogical(MyBase.PointToClient(screenPoint))
        End Function

        Public Sub ShowInfoTip(ByVal [text] As String)
            If ([text] Is Nothing) Then
                Throw New ArgumentNullException("text")
            End If
            Me.workflowToolTip.SetText(String.Empty, [text])
        End Sub

        Public Sub ShowInfoTip(ByVal title As String, ByVal [text] As String)
            If (title Is Nothing) Then
                Throw New ArgumentNullException("title")
            End If
            If ([text] Is Nothing) Then
                Throw New ArgumentNullException("text")
            End If
            Me.workflowToolTip.SetText(title, [text])
        End Sub

        Public Sub ShowInPlaceToolTip(ByVal toolTipText As String, ByVal toolTipRectangle As Rectangle)
            If (toolTipText Is Nothing) Then
                Throw New ArgumentNullException("toolTipText")
            End If
            If toolTipRectangle.IsEmpty Then
                Throw New ArgumentException(SR.GetString("Error_EmptyToolTipRectangle"))
            End If
            Me.workflowToolTip.SetText(toolTipText, toolTipRectangle)
        End Sub

        Private Function System.IServiceProvider.GetService(ByVal serviceType As Type) As Object Implements IServiceProvider.GetService
            Return Me.GetService(serviceType)
        End Function

        <SecurityPermission(SecurityAction.LinkDemand, Flags:=SecurityPermissionFlag.UnmanagedCode)> _
        Private Function System.Windows.Forms.IMessageFilter.PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
            Dim flag As Boolean = False
            If (((m.Msg <> &H100) AndAlso (m.Msg <> 260)) AndAlso ((m.Msg <> &H101) AndAlso (m.Msg <> &H105))) Then
                Return flag
            End If
            Dim control As Control = Control.FromHandle(m.HWnd)
            If ((control Is Nothing) OrElse ((Not control Is Me) AndAlso Not MyBase.Controls.Contains(control))) Then
                Return flag
            End If
            Dim e As New KeyEventArgs((DirectCast(CInt(CLng(m.WParam)), Keys) Or Control.ModifierKeys))
            If ((m.Msg = &H100) OrElse (m.Msg = 260)) Then
                Me.OnKeyDown(e)
            Else
                Me.OnKeyUp(e)
            End If
            Return e.Handled
        End Function

        Private Function TakeWorkflowSnapShot() As Bitmap
            Dim bitmap As Bitmap = Nothing
            Dim rootDesigner As ActivityDesigner = Me.RootDesigner
            If (rootDesigner Is Nothing) Then
                Return bitmap
            End If
            [Using] graphics As Graphics = MyBase.CreateGraphics
                Dim data As ViewPortData
                data = New ViewPortData { _
                    .LogicalViewPort = New Rectangle(Point.Empty, New Size((rootDesigner.Bounds.Width + (2 * DefaultWorkflowLayout.Separator.Width)), (rootDesigner.Bounds.Height + (2 * DefaultWorkflowLayout.Separator.Height)))), _
                    .MemoryBitmap = New Bitmap(data.LogicalViewPort.Width, data.LogicalViewPort.Height, graphics), _
                    .Scaling = New SizeF(1!, 1!), _
                    .Translation = Point.Empty, _
                    .ShadowDepth = New Size(0, 0), _
                    .ViewPortSize = data.LogicalViewPort.Size _
                }
                WorkflowView.TakeWorkflowSnapShot(Me, data)
                Return data.MemoryBitmap
            End [Using]
        End Function

        Friend Shared Sub TakeWorkflowSnapShot(ByVal workflowView As WorkflowView, ByVal viewPortData As ViewPortData)
            Dim memoryBitmap As Bitmap = viewPortData.MemoryBitmap
            [Using] graphics As Graphics = Graphics.FromImage(memoryBitmap)
                graphics.SmoothingMode = SmoothingMode.HighQuality
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic
                workflowView.ActiveLayout.OnPaint(New PaintEventArgs(graphics, viewPortData.LogicalViewPort), viewPortData)
                Dim matrix As New Matrix
                matrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend)
                Dim pts As Point() = New Point() { viewPortData.LogicalViewPort.Location }
                matrix.TransformPoints(pts)
                matrix.Translate(CSng((-pts(0).X + viewPortData.ShadowDepth.Width)), CSng((-pts(0).Y + viewPortData.ShadowDepth.Height)), MatrixOrder.Append)
                graphics.Transform = matrix
                If (Not workflowView.RootDesigner Is Nothing) Then
                    [Using] region As Region = New Region
                        [Using] path As GraphicsPath = ActivityDesignerPaint.GetDesignerPath(workflowView.RootDesigner, False)
                            Dim clip As Region = graphics.Clip
                            [region].MakeEmpty
                            [region].Union(path)
                            graphics.Clip = [region]
                            Dim ambientTheme As AmbientTheme = WorkflowTheme.CurrentTheme.AmbientTheme
                            graphics.FillRectangle(ambientTheme.BackgroundBrush, workflowView.RootDesigner.Bounds)
                            If ambientTheme.ShowGrid Then
                                ActivityDesignerPaint.DrawGrid(graphics, workflowView.RootDesigner.Bounds)
                            End If
                            graphics.Clip = clip
                            Try 
                                DirectCast(workflowView.RootDesigner, IWorkflowDesignerMessageSink).OnPaint(New PaintEventArgs(graphics, viewPortData.LogicalViewPort), viewPortData.LogicalViewPort)
                            Catch exception1 As Exception
                            End Try
                        End [Using]
                    End [Using]
                End If
                Dim e As New PaintEventArgs(graphics, workflowView.RootDesigner.Bounds)
                [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(workflowView, EventArgs.Empty)
                    Dim filter As WorkflowDesignerMessageFilter
                    For Each filter In data.Filters
                        Try 
                            If DirectCast(filter, IWorkflowDesignerMessageSink).OnPaint(e, viewPortData.LogicalViewPort) Then
                                goto Label_01FE
                            End If
                            [Continue] For
                        Catch exception2 As Exception
                            [Continue] For
                        End Try
                    Next
                End [Using]
            Label_01FE:
                graphics.Transform = New Matrix
                If Not viewPortData.ShadowDepth.IsEmpty Then
                    Dim image As New Bitmap(memoryBitmap)
                    [Using] brush As Brush = New SolidBrush(Color.FromArgb(220, Color.White))
                        graphics.FillRectangle(brush, New Rectangle(Point.Empty, New Size(((memoryBitmap.Size.Width - viewPortData.ShadowDepth.Width) - 1), ((memoryBitmap.Size.Height - viewPortData.ShadowDepth.Height) - 1))))
                    End [Using]
                    Dim imageAttr As New ImageAttributes
                    imageAttr.SetColorKey(viewPortData.TransparentColor, viewPortData.TransparentColor, ColorAdjustType.Default)
                    imageAttr.SetColorKey(viewPortData.TransparentColor, viewPortData.TransparentColor, ColorAdjustType.Bitmap)
                    graphics.DrawImage(image, New Rectangle(-viewPortData.ShadowDepth.Width, -viewPortData.ShadowDepth.Height, memoryBitmap.Width, memoryBitmap.Height), 0, 0, memoryBitmap.Width, memoryBitmap.Height, GraphicsUnit.Pixel, imageAttr)
                    image.Dispose
                End If
            End [Using]
        End Sub

        Private Sub UpdateLayout()
            If (Not Me.layoutEventHandler Is Nothing) Then
                Me.PerformLayout(True)
                Me.InvalidateClientRectangle(Rectangle.Empty)
            End If
        End Sub

        Private Sub UpdateScrollRange()
            If ((Me.ViewPortSize.Width >= 0) AndAlso (Me.ViewPortSize.Height >= 0)) Then
                Dim viewPortSize As Size = Me.ViewPortSize
                Dim size2 As Size = Me.LogicalSizeToClient(Me.activeLayout.Extent)
                Dim size3 As New Size(Math.Min(size2.Width, viewPortSize.Width), Math.Min(size2.Height, viewPortSize.Height))
                If (Me.hScrollBar.Maximum <> size2.Width) Then
                    Me.hScrollBar.Maximum = size2.Width
                End If
                If (Me.vScrollBar.Maximum <> size2.Height) Then
                    Me.vScrollBar.Maximum = size2.Height
                End If
                If (Me.hScrollBar.LargeChange <> size3.Width) Then
                    Me.hScrollBar.SmallChange = (size3.Width / 15)
                    Me.hScrollBar.LargeChange = (size3.Width + 1)
                End If
                If (Me.vScrollBar.LargeChange <> size3.Height) Then
                    Me.vScrollBar.SmallChange = (size3.Height / 15)
                    Me.vScrollBar.LargeChange = (size3.Height + 1)
                End If
                Dim num As Integer = (size2.Width - Me.hScrollBar.LargeChange)
                num = If((num < 0), 0, num)
                If (Me.hScrollBar.Value > num) Then
                    Me.hScrollBar.Value = num
                End If
                Dim num2 As Integer = (size2.Height - Me.vScrollBar.LargeChange)
                num2 = If((num2 < 0), 0, num2)
                If (Me.vScrollBar.Value > num2) Then
                    Me.vScrollBar.Value = num2
                End If
                Me.RefreshDynamicAction
                Dim visible As Boolean = Me.hScrollBar.Visible
                If MyBase.Controls.Contains(Me.hScrollBar) Then
                    Me.hScrollBar.Visible = (Me.hScrollBar.Maximum > viewPortSize.Width)
                End If
                Dim flag2 As Boolean = Me.vScrollBar.Visible
                If MyBase.Controls.Contains(Me.vScrollBar) Then
                    Me.vScrollBar.Visible = (Me.vScrollBar.Maximum > viewPortSize.Height)
                End If
                If ((visible <> Me.hScrollBar.Visible) OrElse (Me.vScrollBar.Visible <> flag2)) Then
                    MyBase.PerformLayout
                    Me.Refresh
                End If
            End If
        End Sub

        <SecurityPermission(SecurityAction.LinkDemand, Flags:=SecurityPermissionFlag.UnmanagedCode), UIPermission(SecurityAction.Assert, Window:=UIPermissionWindow.AllWindows)> _
        Protected Overrides Sub WndProc(ByRef m As Message)
            [Using] data As WorkflowMessageDispatchData = New WorkflowMessageDispatchData(Me, EventArgs.Empty)
                Dim filter As WorkflowDesignerMessageFilter
                For Each filter In data.Filters
                    If DirectCast(filter, IWorkflowDesignerMessageSink).ProcessMessage(m) Then
                        Exit For
                    End If
                Next
                If (m.Msg = &H7B) Then
                    Dim lParam As Integer = CInt(m.LParam)
                    Dim screenMenuPoint As Point = If((lParam <> -1), New Point(lParam), Control.MousePosition)
                    Dim filter2 As WorkflowDesignerMessageFilter
                    For Each filter2 In data.Filters
                        If DirectCast(filter2, IWorkflowDesignerMessageSink).OnShowContextMenu(screenMenuPoint) Then
                            Exit For
                        End If
                    Next
                    m.Result = IntPtr.Zero
                    Return
                End If
            End [Using]
            If ((Not Me.workflowToolTip Is Nothing) AndAlso (m.Msg = &H4E)) Then
                Me.workflowToolTip.RelayParentNotify((m))
            End If
            Try 
                If (m.Result = IntPtr.Zero) Then
                    MyBase.WndProc((m))
                End If
            Catch exception As Exception
                If (Not exception Is CheckoutException.Canceled) Then
                    DesignerHelpers.ShowError(Me, exception)
                End If
            End Try
        End Sub


        ' Properties
        Friend Property ActiveLayout As WorkflowLayout
            Get
                Return Me.activeLayout
            End Get
            Set(ByVal value As WorkflowLayout)
                If (value Is Nothing) Then
                    Throw New ArgumentNullException("Layout cannot be null!")
                End If
                Dim current As Cursor = Cursor.Current
                Try 
                    Cursor.Current = Cursors.WaitCursor
                    Me.activeLayout = value
                    If (Not Me.activeLayout Is DirectCast(Me.PrintDocument, WorkflowPrintDocument).PrintPreviewLayout) Then
                        Me.DefaultLayout = Me.activeLayout
                    End If
                    MyBase.PerformLayout
                    If (Not Me.commandSet Is Nothing) Then
                        Me.commandSet.UpdatePageLayoutCommands(True)
                    End If
                Finally
                    Cursor.Current = current
                End Try
            End Set
        End Property

        Private Property DefaultLayout As WorkflowLayout
            Get
                If (Me.defaultLayout Is Nothing) Then
                    Me.defaultLayout = New WorkflowRootLayout(Me)
                End If
                Return Me.defaultLayout
            End Get
            Set(ByVal value As WorkflowLayout)
                If (value Is Nothing) Then
                    Throw New ArgumentNullException(DR.GetString("Error_WorkflowLayoutNull", New Object(0  - 1) {}))
                End If
                If (Not Me.defaultLayout Is value) Then
                    If (Not Me.defaultLayout Is Nothing) Then
                        Me.defaultLayout.Dispose
                    End If
                    Me.defaultLayout = value
                End If
            End Set
        End Property

        Friend ReadOnly Property DragDropInProgress As Boolean
            Get
                Return Me.dragDropInProgress
            End Get
        End Property

        Public Property EnableFitToScreen As Boolean
            Get
                Return (Not Me.fitAllAction Is Nothing)
            End Get
            Set(ByVal value As Boolean)
                If (Me.EnableFitToScreen <> value) Then
                    If value Then
                        If (Me.fitAllAction Is Nothing) Then
                            Me.fitAllAction = Me.CreateDynamicAction
                        End If
                    ElseIf (Not Me.fitAllAction Is Nothing) Then
                        Me.fitAllAction.Dispose
                        Me.fitAllAction = Nothing
                    End If
                    Me.InvalidateClientRectangle(Rectangle.Empty)
                End If
            End Set
        End Property

        Public ReadOnly Property HScrollBar As HScrollBar
            Get
                Return Me.hScrollBar
            End Get
        End Property

        Friend ReadOnly Property MessageHitTestContext As HitTestInfo
            Get
                Return Me.messageHitTestContexts.Peek
            End Get
        End Property

        Public ReadOnly Property PrintDocument As PrintDocument
            Get
                If (Me.printDocument Is Nothing) Then
                    Me.printDocument = New WorkflowPrintDocument(Me)
                End If
                Return Me.printDocument
            End Get
        End Property

        Public Property PrintPreviewMode As Boolean
            Get
                Return (Me.activeLayout Is DirectCast(Me.PrintDocument, WorkflowPrintDocument).PrintPreviewLayout)
            End Get
            Set(ByVal value As Boolean)
                If (Me.PrintPreviewMode <> value) Then
                    If (value AndAlso (PrinterSettings.InstalledPrinters.Count = 0)) Then
                        DesignerHelpers.ShowError(Me, DR.GetString("ThereIsNoPrinterInstalledErrorMessage", New Object(0  - 1) {}))
                        value = False
                    End If
                    Me.ActiveLayout = If(value, DirectCast(Me.PrintDocument, WorkflowPrintDocument).PrintPreviewLayout, Me.DefaultLayout)
                    If (Not Me.commandSet Is Nothing) Then
                        Me.commandSet.UpdatePageLayoutCommands(True)
                    End If
                    If Me.PrintPreviewMode Then
                        Me.prePreviewZoom = Me.Zoom
                        Me.prePreviewScroll = Me.ScrollPosition
                        Me.Zoom = 40
                    Else
                        Me.Zoom = Me.prePreviewZoom
                        Me.ScrollPosition = Me.prePreviewScroll
                    End If
                End If
            End Set
        End Property

        Public Property RootDesigner As ActivityDesigner
            Get
                Return Me.rootDesigner
            End Get
            Set(ByVal value As ActivityDesigner)
                If (Not Me.rootDesigner Is value) Then
                    Me.DisposeMessageFilters(False)
                    Me.rootDesigner = value
                    If (Not Me.rootDesigner Is Nothing) Then
                        Me.PopulateMessageFilters(False)
                        Me.ActiveLayout = Me.DefaultLayout = Me.rootDesigner.SupportedLayout
                    End If
                    Me.OnRootDesignerChanged
                    MyBase.PerformLayout
                End If
            End Set
        End Property

        Private ReadOnly Property ScaleZoomFactor As Single
            Get
                Return (Me.zoomLevel * Me.activeLayout.Scaling)
            End Get
        End Property

        Public Property ScrollPosition As Point
            Get
                Return New Point(Me.HScrollBar.Value, Me.VScrollBar.Value)
            End Get
            Set(ByVal value As Point)
                Dim hScrollBar As ScrollBar = Me.HScrollBar
                If (Not hScrollBar Is Nothing) Then
                    value.X = Math.Min(value.X, ((hScrollBar.Maximum - hScrollBar.LargeChange) + 1))
                    value.X = Math.Max(value.X, hScrollBar.Minimum)
                    hScrollBar.Value = value.X
                End If
                Dim vScrollBar As ScrollBar = Me.VScrollBar
                If (Not vScrollBar Is Nothing) Then
                    value.Y = Math.Min(value.Y, ((vScrollBar.Maximum - vScrollBar.LargeChange) + 1))
                    value.Y = Math.Max(value.Y, vScrollBar.Minimum)
                    vScrollBar.Value = value.Y
                End If
            End Set
        End Property

        Public Property ShadowDepth As Integer
            Get
                Return Me.shadowDepth
            End Get
            Set(ByVal value As Integer)
                If ((value < 0) OrElse (value > 8)) Then
                    Throw New NotSupportedException(DR.GetString("ShadowDepthException", New Object() { 0, 8 }))
                End If
                If (Me.shadowDepth <> value) Then
                    Me.shadowDepth = value
                    Me.InvalidateClientRectangle(Rectangle.Empty)
                End If
            End Set
        End Property

        Friend Property ShowToolContainer As Boolean
            Get
                Return (Not Me.toolContainer Is Nothing)
            End Get
            Set(ByVal value As Boolean)
                If (Me.ShowToolContainer <> value) Then
                    Try 
                        MyBase.SuspendLayout
                        If value Then
                            Me.toolContainer = New TabControl(DockStyle.Right, AnchorAlignment.Far)
                            MyBase.Controls.Add(Me.toolContainer)
                            Me.EnsureScrollBars(Me.hScrollBar, [TryCast](Me.toolContainer.ScrollBar,VScrollBar))
                            Dim strArray(,) As String(0 To .,0 To .) = New String() { { "MultipageLayoutCaption", "MultipageLayout" }, { "ZoomCaption", "Zoom" }, { "PanCaption", "AutoPan" } }
                            Dim i As Integer
                            For i = 0 To strArray.GetLength(0) - 1
                                Dim image As Bitmap = [TryCast](DR.GetImage(strArray(i, 1)),Bitmap)
                                Dim text As String = DR.GetString(strArray(i, 0), New Object(0  - 1) {})
                                Me.toolContainer.TabStrip.Tabs.Add(New ItemInfo((i + 1), image, [text]))
                            Next i
                            AddHandler Me.toolContainer.TabStrip.TabChange, New SelectionChangeEventHandler([Of] TabSelectionChangeEventArgs)(AddressOf Me.OnTabChange)
                            If (Not Me.commandSet Is Nothing) Then
                                Me.commandSet.UpdatePageLayoutCommands(True)
                                Me.commandSet.UpdateZoomCommands(True)
                                Me.commandSet.UpdatePanCommands(True)
                            End If
                        Else
                            RemoveHandler Me.toolContainer.TabStrip.TabChange, New SelectionChangeEventHandler([Of] TabSelectionChangeEventArgs)(AddressOf Me.OnTabChange)
                            Me.toolContainer.TabStrip.Tabs.Clear
                            MyBase.Controls.Remove(Me.toolContainer)
                            Me.toolContainer.Dispose
                            Me.toolContainer = Nothing
                            Me.EnsureScrollBars(Me.hScrollBar, New VScrollBar)
                        End If
                    Finally
                        MyBase.ResumeLayout(True)
                    End Try
                End If
            End Set
        End Property

        Public ReadOnly Property ViewPortRectangle As Rectangle
            Get
                Return New Rectangle(Me.ScrollPosition, Me.ViewPortSize)
            End Get
        End Property

        Public ReadOnly Property ViewPortSize As Size
            Get
                Dim clientSize As Size = MyBase.ClientSize
                If Me.HScrollBar.Visible Then
                    clientSize.Height = Math.Max(0, (clientSize.Height - Me.HScrollBar.Height))
                End If
                If Me.VScrollBar.Visible Then
                    clientSize.Width = Math.Max(0, (clientSize.Width - Me.VScrollBar.Width))
                End If
                Return clientSize
            End Get
        End Property

        Public ReadOnly Property VScrollBar As VScrollBar
            Get
                Return Me.vScrollBar
            End Get
        End Property

        Public Property Zoom As Integer
            Get
                Return Convert.ToInt32(CSng((Me.zoomLevel * 100!)))
            End Get
            Set(ByVal value As Integer)
                If (Me.Zoom <> value) Then
                    If ((value < 10) OrElse (value > 400)) Then
                        Throw New NotSupportedException(DR.GetString("ZoomLevelException2", New Object() { 10, 400 }))
                    End If
                    Dim hScrollBar As ScrollBar = Me.HScrollBar
                    Dim vScrollBar As ScrollBar = Me.VScrollBar
                    If ((Not hScrollBar Is Nothing) AndAlso (Not vScrollBar Is Nothing)) Then
                        Dim empty As PointF = DirectCast(Point.Empty, PointF)
                        Dim point As New Point(Me.ScrollPosition.X, Me.ScrollPosition.Y)
                        empty = New PointF((CSng(point.X) / CSng(hScrollBar.Maximum)), (CSng(point.Y) / CSng(vScrollBar.Maximum)))
                        Me.zoomLevel = (CSng(value) / 100!)
                        Me.UpdateScrollRange
                        Dim point2 As New Point(CInt((hScrollBar.Maximum * empty.X)), CInt((vScrollBar.Maximum * empty.Y)))
                        Me.ScrollPosition = New Point(point2.X, point2.Y)
                        If (Not Me.rootDesigner Is Nothing) Then
                            Me.rootDesigner.Location = Me.activeLayout.RootDesignerAlignment
                        End If
                        Me.InvalidateClientRectangle(Rectangle.Empty)
                        Me.activeLayout.Update(Nothing, LayoutUpdateReason.ZoomChanged)
                        Dim service As IUIService = [TryCast](Me.GetService(GetType(IUIService)),IUIService)
                        If (Not service Is Nothing) Then
                            service.SetUIDirty
                        End If
                        If (Not Me.commandSet Is Nothing) Then
                            Me.commandSet.UpdateZoomCommands(True)
                        End If
                        Me.OnZoomChanged
                    End If
                End If
            End Set
        End Property


        ' Fields
        Private activeLayout As WorkflowLayout
        Private commandSet As CommandSet
        Private customMessageFilters As List([Of] WorkflowDesignerMessageFilter)
        Private defaultLayout As WorkflowLayout
        Private dragDropInProgress As Boolean
        Private ensureVisibleEventHandler As EventHandler
        Private fitAllAction As DynamicAction
        Private hScrollBar As HScrollBar
        Private idleEventHandler As EventHandler
        Private idleEventListeners As EventHandler
        Private layoutEventHandler As EventHandler
        Private messageHitTestContexts As Stack([Of] HitTestInfo)
        Private prePreviewScroll As Point
        Private prePreviewZoom As Integer
        Private printDocument As WorkflowPrintDocument
        Private rootDesigner As ActivityDesigner
        Private serviceProvider As IServiceProvider
        Private shadowDepth As Integer
        Private stockMessageFilters As List([Of] WorkflowDesignerMessageFilter)
        Friend Const ThemeXml As String = "<AmbientTheme xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/workflow"" ApplyTo=""System.Workflow.ComponentModel.Design.WorkflowView"" ShowConfigErrors=""True"" DrawShadow=""False"" DrawGrayscale=""False"" DropIndicatorColor=""0xFF006400"" SelectionForeColor=""0xFF0000FF"" SelectionPatternColor=""0xFF606060"" ForeColor=""0xFF808080"" BackColor=""0xFFFFFFFF"" ShowGrid=""False"" GridColor=""0xFFC0C0C0"" TextQuality=""Aliased"" DrawRounded=""True"" ShowDesignerBorder=""True"" />"
        Private toolContainer As TabControl
        Private viewPortBitmap As Bitmap
        Private vScrollBar As VScrollBar
        Private workflowToolTip As WorkflowToolTip
        Private zoomLevel As Single

        ' Nested Types
        Private Enum TabButtonIds
            ' Fields
            MultiPage = 1
            Pan = 3
            Zoom = 2
        End Enum

        Private NotInheritable Class WorkflowMessageDispatchData
            Implements IDisposable
            ' Methods
            Public Sub New(ByVal workflowView As WorkflowView, ByVal e As EventArgs)
                Me.workflowView = workflowView
                If ((Not Me.workflowView.RootDesigner Is Nothing) AndAlso (Me.workflowView.stockMessageFilters.Count > 0)) Then
                    Dim empty As Point = Point.Empty
                    If (TypeOf e Is MouseEventArgs OrElse TypeOf e Is DragEventArgs) Then
                        If TypeOf e Is MouseEventArgs Then
                            empty = New Point(DirectCast(e, MouseEventArgs).X, DirectCast(e, MouseEventArgs).Y)
                        ElseIf TypeOf e Is DragEventArgs Then
                            empty = Me.workflowView.PointToClient(New Point(DirectCast(e, DragEventArgs).X, DirectCast(e, DragEventArgs).Y))
                            Me.workflowView.UpdateLayout
                        End If
                        Dim point As Point = Me.workflowView.ClientPointToLogical(empty)
                        Dim info As HitTestInfo = Me.workflowView.RootDesigner.HitTest(point)
                        Me.messageContext = If((Not info Is Nothing), info, HitTestInfo.Nowhere)
                        Me.workflowView.messageHitTestContexts.Push(Me.messageContext)
                    End If
                End If
            End Sub

            Private Sub System.IDisposable.Dispose() Implements IDisposable.Dispose
                If ((Not Me.workflowView Is Nothing) AndAlso (Not Me.messageContext Is Nothing)) Then
                    Dim messageContext As HitTestInfo = Me.messageContext
                    Me.workflowView.messageHitTestContexts.Pop
                End If
            End Sub


            ' Properties
            Public ReadOnly Property Filters As ReadOnlyCollection([Of] WorkflowDesignerMessageFilter)
                Get
                    Dim list As New List([Of] WorkflowDesignerMessageFilter)
                    list.AddRange(Me.workflowView.customMessageFilters)
                    list.AddRange(Me.workflowView.stockMessageFilters)
                    Return list.AsReadOnly
                End Get
            End Property


            ' Fields
            Private messageContext As HitTestInfo
            Private workflowView As WorkflowView
        End Class
    End Class
End Namespace

